package com.weilai.dao;

import com.weilai.domain.Follows;

import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface FollowersDao {
    @Select("SELECT * FROM follows WHERE following_id=#{id}")
    public List<Follows> selectFansById(int id);

    @Select("SELECT * FROM follows WHERE follower_id=#{id}")
    public List<Follows> selectFollowingsById(int id);

    //关注他人
    @Insert("INSERT INTO follows values (#{followId},#{followingId},#{createdTime})")
    public void followOthers(int followId,int followingId,String createdTime);

    @Update("UPDATE users SET follower_count=follower_count+1 WHERE id=#{followingId} ")
    public void updateFollowOthersByFollowingId(int followingId);
    @Update("UPDATE users SET subscription=subscription+1 WHERE id=#{followerId} ")
    public void updateFollowOthersBySubscription(int followerId);
    @Select("SELECT * FROM follows where follower_id=#{myId} and following_id=#{userId}")
    public Follows isFan(int myId,int userId);

    @Select("SELECT * FROM follows where follower_id=#{myId} and following_id=#{userId}")
    public Follows isFollowing(int myId,int userId);

    // 按 userid 删除关注信息
    @Delete("DELETE FROM follows WHERE follower_id = #{userId} or following_id = #{userId}")
    void deleteUserById(int userId);

    //取消关注
    @Delete("DELETE FROM follows WHERE  follower_id=#{followerId} and following_id=#{followingId}")
    public void cancelFollow(int followerId,int followingId);
    @Update("UPDATE users SET follower_count=follower_count-1 WHERE id=#{followingId} ")
    public void cancelFollowOthersByFollowingId(int followingId);
    @Update("UPDATE users SET subscription=subscription-1 WHERE id=#{followerId} ")
    public void cancelFollowOthersBySubscription(int followerId);
}


